package com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.supplier;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.UserAttrSupplier;
import com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.UserInfoHelper;
import com.iwhalecloud.bss.kite.dataservice.cache.AttrValueCache;
import com.iwhalecloud.bss.kite.dataservice.entity.AttrValue;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * 14 计费周期 ORD10235
 */
@Service
@UserAttrSupplier(attrField = LocalKeyConsts.IS_VIK)
public class IsVikSupplier extends AbstractUserAttrSupplier {

    @Override
    public String getValue() {
        String isVik = UserInfoHelper
            .getValueFromUserItemInfoMap(userInfoContext.getUserItemInfoMap(), LocalKeyConsts.IS_VIK);
        if (KiteStringUtils.isEmpty(isVik)) {
            isVik = UserInfoHelper
                .getValueFromUserItemInfoMap(userInfoContext.getUserItemInfoMap(), LocalKeyConsts.IS_VIK_NEW);
        }
        return isVik;
    }

    @Override
    public String getValueDesc() {
        String isVik = getValue();
        return Optional.ofNullable(AttrValueCache.getAttrValue("2020012103", isVik))
            .map(AttrValue::getAttrValueName).orElse(isVik);
    }
}
